﻿using AutoMapper;
using HamcoWcs.Contract.ContractCommon;
using HamcoWcs.Contract.ContractLcd;
using HamcoWcs.DAL;
using HamcoWcs.Models.Common;
using HamcoWcs.Models.LcdInfos;
using Microsoft.AspNetCore.Mvc;

namespace HamcoWcs.Main.Controllers.Lcd
{
    /// <summary>
    /// Lcd消息接口
    /// </summary>
    public class LcdController : BasicController
    {
        private readonly ILcdService _lcdService;

        public LcdController(ILcdService lcdService,ILoggerService logger, IMapper mapper, WcsDbContext wcsDbContext) : base(logger, mapper, wcsDbContext)
        {
            _lcdService = lcdService;
        }

        public override string ControllerName => "LcdController";



        /// <summary>
        /// 获取Lcd列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetLcdList()
        {
            try
            {
                var list = _lcdService.GetLcdNames();
                var result = new LcdListResult() { LcdNameList = list };
                return Json(result);
            }
            catch (System.Exception)
            {
                return Json(ForeEndResult.Fail("获取Lcd列表失败"));
            }
        }

        /// <summary>
        /// 获取LcdName对应的Msg
        /// </summary>
        /// <param name="lcdName"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetLcdMsg(string lcdName)
        {
            try
            {
                var msgs = _lcdService.GetLcdMsg(lcdName);
                var result = new LcdMsgResult() { LcdMsgList = msgs };
                return Json(new ForeEndResult(result));
            }
            catch (System.Exception)
            {
                return Json(ForeEndResult.Fail($"获取{lcdName}消息失败"));
            }

        }

        [HttpGet]
        public IActionResult GetLcdListH5()
        {
            try
            {
                var list = _lcdService.GetLcdNames();
                return Json(list);
            }
            catch (System.Exception)
            {
                return Json(ForeEndResult.Fail("获取Lcd列表失败"));
            }
        }


        [HttpGet]
        public IActionResult GetLcdMsgH5(string lcdName)
        {
            try
            {
                var msgs = _lcdService.GetLcdMsg(lcdName);
                return Json(msgs);
            }
            catch (System.Exception)
            {
                return Json(ForeEndResult.Fail($"获取{lcdName}消息失败"));
            }
        }

    }
}
